import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Hex;
import p12.P12Util;

import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.Signature;
import java.security.SignatureException;

public class Test5 {
    public static void main(String[] args) throws NoSuchAlgorithmException, InvalidKeyException, SignatureException, DecoderException {
        Signature signature= Signature.getInstance("SHA256WithRSA");
        signature.initSign(P12Util.getPrivateKey());
        signature.update("黄飞".getBytes(StandardCharsets.UTF_8));


        Signature signature2= Signature.getInstance("SHA256WithRSA");
        signature2.initVerify(P12Util.getPublicKey());
        signature2.update("黄飞".getBytes(StandardCharsets.UTF_8));
        boolean verify = signature2.verify(signature.sign());
        System.out.println(verify);


        System.out.println(Hex.encodeHexString(signature.sign()));

    }
}
